home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / MPW IIGS Interfaces / PIIGSIncludes / SANE.p < prev    next >
Encoding:
Text File  |  1990-05-03  |  6.6 KB  |  263 lines  |  [TEXT/MPS ]

  1. {********************************************
  2. ; File: SANE.p
  3. ;
  4. ;
  5. ; Copyright Apple Computer, Inc. 1986-90
  6. ; All Rights Reserved
  7. ;
  8. ********************************************}
  9.  
  10. UNIT SANE;
  11. INTERFACE
  12. USES TYPES;
  13. CONST
  14.  
  15.  
  16. { Decimal Representation Constants }
  17. SIGDIGLEN = $001C;
  18. DecStrLen = $00FF;
  19.  
  20. { IEEE defualt environment constant }
  21. IEEEDEFAULTENV = $0000;
  22.  
  23. { Decimal formatting styles }
  24. FLOATDECIMAL = $0000;
  25. FIXEDDECIMAL = $0001;
  26.  
  27. { Exceptions }
  28. INVALID = $0001;
  29. UNDERFLOW = $0002;
  30. OVERFLOW = $0004;
  31. DIVBYZERO = $0008;
  32. INEXACT = $0010;
  33.  
  34. TYPE
  35.  
  36. { Ordering relations }
  37. relop = (GREATERTHAN,LESSTHAN,EQUALTO,UNORDERED);
  38.  
  39. { Inquiry classes }
  40. numclass = (SNAN,QNAN,INFINITE,ZERONUM,NORMALNUM,DENORMALNUM);
  41.  
  42. { Environmental control }
  43.  
  44. { Rounding directions }
  45. rounddir = (TONEAREST,UPWARD,DOWNWARD,TOWARDZERO);
  46.  
  47. { Rounding precisions }
  48. roundpre = (EXTPRECISION,DBLPRECISION,FLOATPRECISION);
  49. exception = Integer ;
  50. environment = Integer ;
  51. decimal = RECORD
  52.     sgn : Integer; { 0 for positive, 1 for negative  }
  53.     exp : Integer;
  54.     sig : STRING[SigDigLen];
  55. END;
  56. decform = RECORD
  57.     style : Integer; { FLOATDECIMAL or FIXEDDECIMAL  }
  58.     digits : Integer;
  59. END;
  60. DecStr = STRING[DecStrLen];
  61. CStrPtr = ^CHAR;
  62.  
  63. haltvector = VoidProcPtr;
  64.  
  65. { Conversions between numeric binary types }
  66. FUNCTION  Num2Integer ( x:Extended) : Integer ;
  67. {   }
  68.  
  69. FUNCTION  Num2Longint ( x:Extended) : Longint ;
  70. {   }
  71.  
  72. FUNCTION  Num2Real ( x:Extended) : Real ;
  73. {   }
  74.  
  75. FUNCTION  Num2Double ( x:Extended) : Double ;
  76. {   }
  77.  
  78. FUNCTION  Num2Extended ( x:Extended) : Extended ;
  79. {   }
  80.  
  81. FUNCTION  Num2Comp ( x:Extended) : Comp ;
  82. {   }
  83.  
  84.  
  85. { Conversions between binary and decimal }
  86. PROCEDURE num2dec ( f:DecForm; x:extended;VAR d:Decimal)  ; C;
  87. { d <-- x according to format f }
  88.  
  89. FUNCTION  dec2num (VAR d:Decimal) : Extended ; C;
  90. { Dec2Num <-- d as Extended }
  91.  
  92. PROCEDURE Num2Str ( f:DecForm; x:Extended;VAR s:DecStr)  ;
  93. { s <-- x according to format f }
  94.  
  95. FUNCTION  Str2Num ( s:DecStr) : Extended ;
  96. { Str2Num <-- s }
  97.  
  98.  
  99. { Conversions between decimal formats }
  100. PROCEDURE str2dec ( s:DecStr;VAR index:Integer;VAR d:Decimal;VAR validPrefix:Integer)  ;
  101. { Input: Index is starting index into s. }
  102. { Output: Index is 1 + (index of last character of longest numeric substring). }
  103. { d <-- Decimal rep of longest numeric substring; }
  104. { validPrefix <-- s, beginning at Index, contains valid numeric string }
  105.  
  106. PROCEDURE CStr2Dec ( s:CStrPtr;VAR index:Integer;VAR d:Decimal;VAR validPrefix:Integer)  ;
  107. { For character buffers or C strings instead of Pascal strings. }
  108. { The first arg is the address of a character buffer. }
  109. { validPrefix <-- scanning ended with a null byte }
  110.  
  111. PROCEDURE dec2str ( f:DecForm; d:Decimal;VAR s:DecStr)  ;
  112. { s <-- d according to format f }
  113.  
  114.  
  115. { Arithmetic, auxiliary and elementary functions }
  116. FUNCTION  remainder ( x:Extended; y:Extended;VAR quo:Integer) : Extended ; C;
  117. { Remainder <-- x rem y; }
  118. { quo <-- 7 low-order bits of integer quotient x/y }
  119. { where -127 < quo < 127 }
  120.  
  121. FUNCTION  rint ( x:Extended) : Extended ;
  122. { round to integral value }
  123.  
  124. FUNCTION  scalb ( n:Integer; x:Extended) : Extended ; C;
  125. { scale binary; scalb <-- x * 2^n }
  126.  
  127. FUNCTION  logb ( x:Extended) : Extended ; C;
  128. { binary log: binary exponent of normalized x }
  129.  
  130. FUNCTION  copysign ( x:Extended; y:Extended) : Extended ;
  131. { CopySign <-- y with sign of x }
  132.  
  133. FUNCTION  NextReal ( x:Real; y:Real) : Real ;
  134. { next Real rep after (Real) x in direction of (Real) y }
  135.  
  136. FUNCTION  nextdouble ( x:Double; y:Double) : Double ; C;
  137. { next Double rep after (Double) x in direction of (Double) y }
  138.  
  139. FUNCTION  nextextended ( x:Extended; y:Extended) : Extended ; C;
  140. { next extended representation after x in direction of y }
  141.  
  142. FUNCTION  log2 ( x:Extended) : Extended ; C;
  143. { base-2 logarithm }
  144.  
  145. FUNCTION  Ln1 ( x:Extended) : Extended ;
  146. { ln(1 + x) }
  147.  
  148. FUNCTION  exp2 ( x:Extended) : Extended ; C;
  149. { base-2 exponential }
  150.  
  151. FUNCTION  exp1 ( x:Extended) : Extended ; C;
  152. { exp(x) - 1 }
  153.  
  154. FUNCTION  XpwrY ( x:Extended; y:Extended) : Extended ;
  155. { general exponential: x ^ i }
  156.  
  157. FUNCTION  XpwrI ( x:Extended; i:Integer) : Extended ;
  158. { integer exponential: x ^ i }
  159.  
  160. FUNCTION  compound ( r:Extended; n:Extended) : Extended ; C;
  161. { compound: (1 + r) ^ n }
  162.  
  163. FUNCTION  annuity ( r:Extended; n:Extended) : Extended ; C;
  164. { Annuity <-- (1 - (1+r)^(-n)) / r }
  165.  
  166. FUNCTION  tan ( x:Extended) : Extended ; C;
  167. { tangent }
  168.  
  169. FUNCTION  randomx (VAR x:Extended) : Extended ; C;
  170. { returns next random number; updates x; }
  171. { x must be integral, 1 <= x <= 2^31 - 2 }
  172.  
  173.  
  174. { Inquiry Routines }
  175. FUNCTION  ClassReal ( x:Real) : numclass ;
  176. { class of (Real) x }
  177.  
  178. FUNCTION  classdouble ( x:Double) : numclass ; C;
  179. { class of (Double) x }
  180.  
  181. FUNCTION  classcomp ( x:Comp) : numclass ; C;
  182. { class of (Comp) x }
  183.  
  184. FUNCTION  classextended ( x:Extended) : numclass ; C;
  185. { class of x }
  186.  
  187. FUNCTION  signnum ( x:Extended) : Longint ; C;
  188. { 0 if sign bit clear, 1 if sign bit set }
  189.  
  190.  
  191. { Environment access routines }
  192. PROCEDURE setexception ( e:exception; b:Boolean)  ;
  193. { clears e flags if b is 0, sets e flags otherwise; may cause halt }
  194.  
  195. FUNCTION  testexception ( e:exception) : Boolean ;
  196. { return true if any e flag is set, return false otherwise }
  197.  
  198. PROCEDURE sethalt ( e:exception; b:Boolean)  ;
  199. { set e halt enables if b is true, clear e halt enables otherwise }
  200.  
  201. FUNCTION  testhalt ( e:exception) : Boolean ; C;
  202. { return true if any e halt is enabled, return false otherwise }
  203.  
  204. PROCEDURE setround ( r:rounddir)  ;
  205. { set rounding direction to r }
  206.  
  207. FUNCTION  getround  : rounddir ;
  208. { return rounding direction }
  209.  
  210. PROCEDURE setprecision ( p:roundpre)  ; C;
  211. { sets rnd'n precision to p }
  212.  
  213. FUNCTION  getprecision  : roundpre ; C;
  214.  
  215.  
  216. PROCEDURE setenvironment ( e:environment)  ; C;
  217. { sets SANE environment to e }
  218.  
  219. PROCEDURE getenvironment (VAR e:environment)  ; C;
  220. { e <-- SANE environment }
  221.  
  222. PROCEDURE procentry (VAR e:environment)  ;
  223. { e <-- environment;  environment <-- IEEE default env }
  224.  
  225. PROCEDURE procexit ( e:environment)  ;
  226. { temp <-- current exceptions; }
  227. { SANE environment <-- e; }
  228. { signals exceptions in temp }
  229.  
  230. FUNCTION  gethaltvector  : haltvector ; C;
  231. { return SANE halt vector }
  232.  
  233. PROCEDURE sethaltvector ( v:haltvector)  ; C;
  234. { halt vector <-- v }
  235.  
  236.  
  237. { Comparison routine }
  238. FUNCTION  relation ( x:Extended; y:Extended) : relop ; C;
  239. { return Relation such that "x Relation y" is true }
  240.  
  241.  
  242. { NaNs and Special Constants }
  243. FUNCTION  nan(i: INTEGER): EXTENDED; C;
  244. { returns NaN with code i }
  245.  
  246. PROCEDURE SANEBootInit   ;
  247. PROCEDURE SANEStartUp ( dPageAddr:Integer)  ;
  248. PROCEDURE SANEShutDown   ;
  249. FUNCTION  SANEVersion  : Integer ;
  250. PROCEDURE SANEReset   ;
  251. FUNCTION  SANEStatus  : Integer ;
  252. PROCEDURE SANEFP816   ;
  253. PROCEDURE SANEDecStr816   ;
  254. PROCEDURE SANEElems816   ;
  255. PROCEDURE EnvTrap ( e:environment; i:Integer)  ;
  256.  
  257.  
  258. PROCEDURE VAREnvTrap (VAR e:environment; i:Integer)  ;
  259.  
  260.  
  261. IMPLEMENTATION
  262. END.
  263.